from django.db import models
from django.utils.text import slugify

# 风景详情
class ScenicSpot(models.Model):
    title = models.CharField(max_length=200, verbose_name="标题")
    address = models.CharField(max_length=300, verbose_name="地址")
    description = models.TextField(verbose_name="描述")
    image_Homepage = models.ImageField(upload_to='scenic_spots/', verbose_name="图片")
    image_1 = models.ImageField(upload_to='scenic_spots/', verbose_name="图片")
    image_2 = models.ImageField(upload_to='scenic_spots/', verbose_name="图片")
    slug = models.SlugField(max_length=200, unique=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "风景点"
        verbose_name_plural = "风景点"